package me.zhengjie.modules.system.rest;/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.system.domain.*;
import lombok.RequiredArgsConstructor;
import java.util.List;

import me.zhengjie.modules.system.domain.dto.PokerAwardQueryCriteria;
import me.zhengjie.modules.system.service.PokerAwardService;
import me.zhengjie.modules.system.service.impl.RconServiceImpl;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.utils.PageResult;

/**
* @author greazy
* @date 2025-04-08
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "award")
@RequestMapping("/api/pokerAward")
public class PokerAwardController {

    private final PokerAwardService pokerAwardService;

    private final RconServiceImpl rconService;

    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('pokerAward:list')")
    public void exportPokerAward(HttpServletResponse response, PokerAwardQueryCriteria criteria) throws IOException {
        pokerAwardService.download(pokerAwardService.queryAll(criteria), response);
    }

    @GetMapping
    @ApiOperation("查询award")
    @PreAuthorize("@el.check('pokerAward:list')")
    public ResponseEntity<PageResult<PokerAward>> queryPokerAward(PokerAwardQueryCriteria criteria){
        Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
        return new ResponseEntity<>(pokerAwardService.queryAll(criteria,page),HttpStatus.OK);
    }

    @GetMapping("/award")
    public ResponseEntity<PageResult<PokerAward>> queryAward(PokerAwardQueryCriteria criteria){
        Long userId = SecurityUtils.getCurrentUserId();
        Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
        criteria.setUserId(userId);
        return new ResponseEntity<>(pokerAwardService.queryAll(criteria,page),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增award")
    @ApiOperation("新增award")
    @PreAuthorize("@el.check('pokerAward:add')")
    public ResponseEntity<Object> createPokerAward(@Validated @RequestBody PokerAward resources){
        pokerAwardService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改award")
    @ApiOperation("修改award")
    @PreAuthorize("@el.check('pokerAward:edit')")
    public ResponseEntity<Object> updatePokerAward(@Validated @RequestBody PokerAward resources){
        pokerAwardService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除award")
    @ApiOperation("删除award")
    @PreAuthorize("@el.check('pokerAward:del')")
    public ResponseEntity<Object> deletePokerAward(@ApiParam(value = "传ID数组[]") @RequestBody List<Integer> ids) {
        pokerAwardService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PostMapping(value = "/wtq")
    public ResponseEntity<Object> wtq(Integer serverId,String goodId,Integer num) throws IOException {
        return pokerAwardService.wtq(serverId,goodId,num);
    }

    @PostMapping(value = "/qtw")
    public ResponseEntity<Object> qtw(Integer serverId,String goodId,Integer num) throws IOException {
        return pokerAwardService.qtw(serverId,goodId,num);
    }

    @PostMapping(value = "/s")
    public ResponseEntity<Object> s(Integer awardId) throws IOException {

        return pokerAwardService.s(awardId);
    }

    @PostMapping(value = "/test")
    public ResponseEntity<Object> test(String ip,String port,String password,String commType,String steamId,String goodId,Integer num) throws IOException {
        String s = rconService.sendCommond(ip, port, password, commType, steamId, goodId, num);
        return new ResponseEntity<>(s,HttpStatus.OK);
    }




}